package loader

import (
	"fmt"
	"errors"
	"testing"
	"reflect"
)

func expectError(t *testing.T, name string, kind ErrorContent) {
	var expect_t = reflect.TypeOf(kind)
	var _, _, err = LoadEntry(getTestPath(t, name))
	if err != nil {
		var got_t = reflect.TypeOf(err.Concrete)
		if !(got_t.AssignableTo(expect_t)) {
			t.Fatal(errors.New(fmt.Sprintf(
				"wrong error kind: %s expected but got %s", expect_t, got_t)))
		}
	} else {
		t.Fatal(errors.New("incorrect module passed the loader"))
	}
}

func TestReadModuleFailed0(t *testing.T) {
	expectError(t, "does_not_exist", E_ReadModuleFailed {})
}
func TestReadModuleFailed1(t *testing.T) {
	expectError(t, "read_module_failed_1", E_ReadModuleFailed {})
}
func TestReadModuleFailed2(t *testing.T) {
	expectError(t, "read_module_failed_2", E_ReadModuleFailed {})
}
func TestReadModuleFailed3(t *testing.T) {
	expectError(t, "read_module_failed_3", E_ReadModuleFailed {})
}
func TestParseFailed(t *testing.T) {
	expectError(t, "parse_failed", E_ParseFailed {})
}
func TestDepNameDuplicate(t *testing.T) {
	expectError(t, "dep_name_duplicate", E_DepNameDuplicate {})
}
func TestDepModDuplicate(t *testing.T) {
	expectError(t, "dep_mod_duplicate", E_DepModDuplicate {})
}
func TestDepModCircular(t *testing.T) {
	expectError(t, "dep_mod_circular", E_DepModCircular {})
}
func TestDepModConflict(t *testing.T) {
	expectError(t, "dep_mod_conflict", E_DepModConflict {})
}


